<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 7/10/14
 * Time: 1:07 PM
 */

//use Laravel\Redirect;

class Location_Widget_Popular_Controller extends Base_Controller {

	public $restful = true;

	public function __construct()
	{
		parent::__construct();
		//--Your Code --//
	}


	public function get_index($location=0){
		//--Show Parent Locations--//
		$limit = Config::get('Location::popular.count') ;
		$sql = "SELECT L.* from locations L
		INNER JOIN terms T on L.id = T.value
		AND (T.term='location') AND L.deep = 1

		Limit 0, $limit";
		$result = DB::query($sql);
		//dd($sql);

		$data['location_popular'] = $result;
		return View::make('Location::widget.popular',$data);
	}

	public function get_all(){
		 
		 
		$data['location_parent'] = Locations::parent(0)->get(array('id','name','slug'));
		 
		$this->theme->set_theme("default") ;
		$this->theme->set_layout('column1');
		 
		/*-- META DATA */
		$this->theme->title('All Locations'.' - '.Settings::get('en','site_title'));

		/*-- BREADCRUMB */

		Breadcrumb::addbreadcrumb('Home', URL::base());
		Breadcrumb::addbreadcrumb('All Locations');
		Breadcrumb::setSeparator('&raquo;');

		$data['breadcrumb'] = Breadcrumb::generate();
		 
		return $this->theme->render('location::widget.location_all',$data);
		 
	}

	public function get_location($slug=''){
		
		$locid = Locations::where('slug','=',$slug)->first();
		
		
		$data['location_parent'] = Locations::parent($locid->id)->get(array('id','name','slug'));
		
		
		$this->theme->set_theme("default") ;
		$this->theme->set_layout('column1');
		
		Breadcrumb::addbreadcrumb('Home', URL::base());
		Breadcrumb::addbreadcrumb('Location all', URL::base().'/'.'location/all');
		Breadcrumb::addbreadcrumb($locid->name, URL::base());
		Breadcrumb::setSeparator('&raquo;');
		
		$data['breadcrumb'] = Breadcrumb::generate();
		return $this->theme->render('Location::widget.location_all',$data);
		 
	}
}